﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace EzDesk.MobileWeb.Extensions
{
    public static class HtmlHelperExtensions
    {
        public static string ReturnButton(this HtmlHelper html)
        {
            string returnUrl = html.ViewData["r"] as String;
            if (String.IsNullOrEmpty(returnUrl))
            {
                string controllerObjName = html.ViewContext.Controller.GetType().Name;
                string controllerName = controllerObjName.Remove(controllerObjName.Length - 10);
                
                //todo: 跳转到相应 Controller 的Index页面 html.ViewContext.Controller
                //跳转到首页
                html.ActionLink("返回", "Index", controllerName);
            }
            return String.Format(
                "<a href = \"{0}\">返回</a>",
                returnUrl
                );
        }
    }
}
